/*******************************************************************************
 * @note Copyright (C) 2023 Shanghai Panchip Microelectronics Co., Ltd. All rights reserved.
 *
 * @file display.c
 * @brief
 *
 * @history - V0.8, 2024-4
*******************************************************************************/
#include "oled.h"
#include "pan_rf.h"
#include "display.h"
#include "key_handle.h"

/* user can change frequency list, FREQ_LIST_NUM defined in display.h*/
uint32_t freq_list[FREQ_LIST_NUM] = {RF_FREQ_DEFAULT/100000, 4910, 5100};

extern uint32_t g_UserTxMode;
static char txmode[4] = {'A', 'B', 'C', 'D'};
static char test_mode1[3] = {' ', '1', '2'};
static char *bw[9] = {"0", "0", "0", "0", "0", "62.5", "125 ", "250 ", "500 "};
char *cr[5] = {"0", "4/5", "4/6", "4/7", "4/8"};

void OLED_ShowMenu(void)
{
    oled_show_string(0, 0, "PW:", 16);
    oled_show_string(0, 16, "CR:", 16);
    oled_show_string(0, 32, "BW:", 16);
    oled_show_string(0, 48, "PL:", 16);
    oled_show_string(64, 0, "MODE:", 16);
    oled_show_string(64, 16, "FQ:", 16);
    oled_show_string(64, 32, "SF:", 16);

    if (g_UserTxMode)
    {
        oled_show_string(64, 48, "TX:", 16);
    }
    else
    {
        oled_show_string(64, 48, "RX:", 16);
    }
    
    dis_init();
    
    oled_refresh();
}

void dis_err(char *str)
{
    oled_clear();
    oled_show_string(0, 22, str, 16);
    oled_refresh();
}

void dis_set_sf(uint32_t val)
{
    oled_show_num(85, 32, val, 4, 16);
}

void dis_set_bw(uint32_t val)
{
    oled_show_string(30, 32, bw[val - 1], 16);
}

void dis_set_pl(uint32_t val)
{
    oled_show_num(20, 48, val, 4, 16);
}

void dis_set_mode(uint32_t val)
{
    oled_show_char(103, 0, txmode[val], 16, 1);
}

void dis_set_test_mode1(uint32_t val)
{
    oled_show_char(110, 0, test_mode1[val], 16, 1);
}

void dis_set_cr(uint32_t val)
{
    oled_show_string(30, 16, cr[val], 16);
}

void dis_set_fq(uint32_t val)
{
    oled_show_num(85, 16, val, 4, 16);
}

void dis_set_cnt(uint32_t val)
{
    oled_show_num(85, 48, val, 4, 16);
}

void dis_set_txpower(uint32_t val)
{
    oled_show_num(22, 0, val, 4, 16);
}

void dis_set_carrier_power(uint32_t val)
{
    oled_show_string(32, 48, "POWER:", 16);
    oled_show_num(85, 48, val, 4, 16);
}

void refresh_frame(void)
{
    oled_refresh();
}
